#include "ObjectManager.h"
#include "Camera.h"
#include "IObject.h"

#include <cassert>


CObjectManager* CObjectManager::s_Instance = nullptr;


CObjectManager* CObjectManager::GetInstance( void )
{
	if( s_Instance == nullptr )
		s_Instance = new CObjectManager;


	return s_Instance;
}


void CObjectManager::DeleteInstance( void )
{
	delete s_Instance;
	s_Instance = nullptr;
}


CObjectManager::CObjectManager(void)
{
	m_bPaused = false;
}


CObjectManager::~CObjectManager(void)
{
}


void CObjectManager::AddObject( IObject* pObject )
{
	assert( pObject != nullptr && "CObjectManager::AddObject - null parameter" );
	m_Objects.push_back( pObject );

	pObject->AddRef();
}


void CObjectManager::RemoveObject( IObject* pObject )
{
	assert( pObject != nullptr && "CObjectManager::RemoveObject - null parameter" );

	for( ObjectIter iter = m_Objects.begin(); iter != m_Objects.end(); ++iter )
	{
		if( (*iter) == pObject )
		{
			pObject->Release();

			m_Objects.erase( iter );
			break;
		}
	}
}


void CObjectManager::RemoveAllObjects( void )
{
	for( ObjectIter iter = m_Objects.begin(); iter != m_Objects.end(); ++iter )
	{
		(*iter)->Release();
	}

	m_Objects.clear();
}


void CObjectManager::UpdateAllObjects( float fElapsedTime )
{
	if( m_bPaused == true )
		return;

	for( ObjectIter iter = m_Objects.begin(); iter != m_Objects.end(); ++iter )
	{
		(*iter)->Update( fElapsedTime );
		
	}
			
}


void CObjectManager::PauseAllObjects( void )
{

}

